package tragame.game;

import java.rmi.RemoteException;

import tragame.game.Resource.ResourceType;
import tragame.interfaces.IBuildingProd;
import tragame.interfaces.IResource;

/**
 * This class only concerns production buildings that have the distinctiveness to
 * change the amount of resource on a square
 * @author jing
 *
 */
public class BuildingProd extends Building implements IBuildingProd{
	
	private static final long serialVersionUID = 1L;
	
	private Resource resource;
	
	public enum BuildingProdType {
		Scierie, Ferme, Mine, CARRIERE;
		public BuildingType getBuildingType() {
			switch(this) {
				case CARRIERE:
					return BuildingType.CARRIERE;
				case Ferme:
					return BuildingType.Ferme;
				case Mine:
					return BuildingType.Mine;
				default:
					return BuildingType.Scierie;
			}
		}
		public ResourceType getResourceType() {
			switch(this) {
				case CARRIERE:
					return ResourceType.terre;
				case Ferme:
					return ResourceType.nourriture;
				case Mine:
					return ResourceType.fer;
				default:
					return ResourceType.bois;
			}
		}
	}
	
	public BuildingProd(BuildingProdType type) throws RemoteException {
		super(type.getBuildingType());
		initialize(type);
	}
	
	private void initialize(BuildingProdType type) throws RemoteException{
		this.resource = new Resource(type.getResourceType());
	}
	
	public IResource getRessource(){
		return (IResource)this.resource;
	}
	
	public void createBuilding(){
		int oldProduction = this.resource.getProduction();
		this.resource.setProduction(oldProduction+1000);
	}
	
	public void upgradeBuilding(){
		int oldProduction = this.resource.getProduction();
		this.resource.setProduction(oldProduction*2);
	}
}
